/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.xtd.facede.retail;

import com.xtd.facade.AbstractFacade;
import com.xtd.facade.SystemException;
import com.xtd.model.retail.Account;
import java.util.List;
import javax.ejb.Stateless;

/**
 *
 * @author Lu Yuanbin
 */
@Stateless
public class AccountFacade extends AbstractFacade<Account> {

    public AccountFacade() {
        super(Account.class);
    }

    public List<Account> find(String searchContent) {
        if (searchContent == null) {
            searchContent = "";
        }
        return getEntityManager().createQuery("select a from Account as a where a.mname like :searchContent or a.fname like :searchContent or a.mphone like :searchContent or a.fphone like :searchContent or a.phone like :searchContent").setParameter("searchContent", "%" + searchContent + "%").getResultList();
    }

    public void update(Account account) {
        if(account.getId()== null) {
            create(account);
        } else {
            edit(account);
        }
    }

    public List<Account> findDuplicatePhone(Account account) {
        return getEntityManager().createQuery("select a from Account as a where a.mphone = :mphone or a.fphone = :fphone or a.phone = :phone").setParameter("mphone", account.getMphone()).setParameter("fphone", account.getFphone()).setParameter("phone", account.getPhone()).getResultList();
    }
}
